<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Gallery_model extends CI_Model {

	function __construct(){
		parent::__construct();

	}

	//--show = 1: index Page 2: inner page
	function getBanner($show=NULL,$limit=1){
		$sql = "select * from gallery where (impressions < max_impressions or max_impressions = 0) and shows = $show and term='banner' and status=51 limit 0,$limit";
		//$sql = "select * from gallery where (impressions < max_impressions or max_impressions = 0) and shows ='$show' and status=51 or shows = 0 limit $limit ";
		$query = $this->db->query($sql);
		$result = $query->result();
		if($result){
			return $result;
		}else{
			return false;
		}
	}
	
	function getbnnrcat($cat_id = 0)
	{
		$sql = "Select * from gallery where (impressions < max_impressions or max_impressions = 0) and cat_id = $cat_id and shows=3 and status=51 order by id desc limit 3";
		$query = $this->db->query($sql);
		if($query->num_rows() > 0){
			$result = $query->result(); 
			return $result;
		}else{
			return FALSE;
		}
	}

	function getGallery($postID = 0, $term = '', $limit = 1){
		$sql = "select * from gallery where post_id = $postID and term = '$term' limit 0,$limit";
		$query = $this->db->query($sql);
		if($query->num_rows() > 0){
			$result = $query->result(); 
			return $result;
		}else{
			return FALSE;
		}
	}


	

	

}